package xj.model.uml;

import static xj.model.uml.UMLModelConstants.ATTR_BODY;
import static xj.model.uml.UMLModelConstants.ATTR_LANG;
import static xj.model.uml.UMLModelConstants.ATTR_NAME;
import xj.meta.AbstractModelElement;

public class Constraint extends AbstractModelElement {

  public Constraint() {
    this(null, null, null);
  }

  public Constraint(String body) {
    this(null, null, body);
  }

  public Constraint(String name, String lang, String body) {
    setName(name);
    setLang(lang);
    setBody(body);
    destructable = false;
    preserved = true;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
    setAttribute(ATTR_NAME, name);
  }

  public String getLang() {
    return lang;
  }

  public void setLang(String lang) {
    this.lang = lang;
    setAttribute(ATTR_LANG, lang);
  }

  public String getBody() {
    return body;
  }

  public void setBody(String body) {
    this.body = body;
    setAttribute(ATTR_BODY, body);
  }

  @Override
  public String toString() {
    return "Constraint: name=" + name + " lang=" + lang + " body=" + body;
  }

  @Override
  protected boolean asElement(String attrName) {
    if (attrName != null) {
      return (attrName.equals(ATTR_BODY));
    }
    return false;
  }

  @Override
  protected boolean inCDATASection(String name) {
    return asElement(name);
  }

  @Override
  public Object clone() throws CloneNotSupportedException {
    Constraint c = (Constraint) super.clone();
    c.setName(name);
    c.setLang(lang);
    c.setBody(body);
    return c;
  }

  protected String name;

  protected String lang;

  protected String body;

}
